<template>
	<view class="profile">
		<cu-custom bgColor="bg-gradual-orange" :isBack="true">
			<block slot="content">修改密码</block>
		</cu-custom>
		<view class="cu-form-group">
			<view class="title">UID</view>
			<input :value="userInfo.id" disabled=""></input>
		</view>
		<!-- <view class="cu-form-group">
			<view class="title">手机号</view>
			<input v-model="form.mobile" disabled=""></input>
		</view> -->
		<view class="cu-form-group">
			<view class="title">原密码</view>
			<input type="password" v-model="form.oldPassword"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">新密码</view>
			<input type="password" v-model="form.password"></input>
		</view>


		<view class="padding flex flex-direction">
			<button class="cu-btn bg-gradual-orange margin-tb-sm lg" @tap="profile">修改密码</button>
		</view>


	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import user from '@/api/user.js';
	export default {
		data() {
			return {
				form: {
					oldPassword: '',
					password: "",
					// mobile: ''
				}
			}
		},
		computed: {
			...mapState(['userInfo']),
		},
		onLoad() {
			this.form.mobile = this.userInfo.mobile
		},
		methods: {
			profile() {

				user.changePwd(this.form).then(res => {
					uni.hideLoading();
					if (res.code !== 1) {
						return this.toast(res.msg)
					}
					if (res.code === 1) {
						this.$store.commit('logout');
						uni.redirectTo({
							url: '/pages/my/login'
						})
						// 	uni.navigateBack();
					}
				})
			},
			logout() {
				// 登录账号
				user.logout().then(res => {
					uni.hideLoading();
					if (res.code !== 1) {
						return this.toast(res.msg)
					}
					if (res.code === 1) {
						this.$store.commit('logout');
						uni.navigateBack();
					}
				})
			},
		}
	}
</script>

<style>

</style>